#include "GameModeManager.h"


namespace infinity {

GameModeManager::GameModeManager()
{
}

GameModeManager::~GameModeManager()
{
	for (GameModes::iterator gamemode = m_gamemodes.begin(); gamemode != m_gamemodes.end(); ++gamemode)
	{
		delete *gamemode;
	}

	m_gamemodes.clear();
}

void GameModeManager::install()
{
	for (GameModes::iterator gamemodeIt = m_gamemodes.begin(); gamemodeIt != m_gamemodes.end(); ++gamemodeIt)
	{
		GameMode* gamemode = *gamemodeIt;
		gamemode->install();
	}
}

void GameModeManager::update(const dw::float32 dt)
{
	for (GameModes::iterator gamemodeIt = m_gamemodes.begin(); gamemodeIt != m_gamemodes.end(); ++gamemodeIt)
	{
		GameMode* gamemode = *gamemodeIt;
		gamemode->update(dt);
	}
}

void GameModeManager::render()
{
	for (GameModes::iterator gamemodeIt = m_gamemodes.begin(); gamemodeIt != m_gamemodes.end(); ++gamemodeIt)
	{
		GameMode* gamemode = *gamemodeIt;
		gamemode->render();
	}
}

void GameModeManager::renderDebug()
{
	for (GameModes::iterator gamemodeIt = m_gamemodes.begin(); gamemodeIt != m_gamemodes.end(); ++gamemodeIt)
	{
		GameMode* gamemode = *gamemodeIt;
		gamemode->renderDebug();
	}
}

void GameModeManager::term()
{
	for (GameModes::iterator gamemodeIt = m_gamemodes.begin(); gamemodeIt != m_gamemodes.end(); ++gamemodeIt)
	{
		GameMode* gamemode = *gamemodeIt;
		gamemode->term();
	}
}

void GameModeManager::addGameMode(GameMode * gamemode)
{
	m_gamemodes.push_back(gamemode);
}

} // namespace infinity
